package com.wnxy.sddfp.trade.controller;


import com.wnxy.sddfp.common.model.dto.trade.BorrowRecordDTO;
import com.wnxy.sddfp.common.model.page.Pages;
import com.wnxy.sddfp.common.model.query.BorrowQuery;
import com.wnxy.sddfp.common.model.vo.trade.BorrowRecordVo;
import com.wnxy.sddfp.common.result.Result;
import com.wnxy.sddfp.trade.service.IBorrowRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author Jet
 * @since 2023-05-08
 */
@RestController
@Api(tags = "交易中心")
public class TradeCenterController {

    @Autowired
    private IBorrowRecordService borrowRecordService;

    /**
     * 借款申请，保存借款记录
     */
    @ApiOperation("借款申请")
    @PostMapping("/trade/borrow/add")
    public Result addBorrowRecord(@RequestBody BorrowRecordDTO borrowRecordDTO) {
        borrowRecordService.addBorrowRecord(borrowRecordDTO);
        return Result.ok();
    }

    /**
     * 借款记录查询
     */
    @ApiOperation("借款记录查询")
    @PostMapping("/trade/borrow/query")
    public Result<Pages<BorrowRecordVo>> queryBorrowRecord(
            @RequestBody BorrowQuery borrowQuery,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        Pages<BorrowRecordVo> pages =
                borrowRecordService.queryBorrowRecord(borrowQuery,pageNum,pageSize);
        return Result.ok(pages);
    }

    /**
     * 借款审核接口，请求参数：借款记录ID、审核状态
     */
    @PutMapping("/trade/borrow/status")
    @ApiOperation("借款审核接口")
    public Result verifyStatus( Long borrowRecordId, String status){
        borrowRecordService.verifyStatus(borrowRecordId,status);
        return Result.ok();
    }
}

